package com.libgdxbar.pvzlikegame.systems.state;

import com.badlogic.gdx.utils.IntMap;
import com.libgdxbar.pvzlikegame.entities.BaseEntity;
import com.libgdxbar.pvzlikegame.entities.EntityListener;
import org.libgdxbar.projects.interfaces.IState;

public class StateSystem extends BaseEntity implements EntityListener {

	private IntMap<IState> stateEntities = new IntMap<>();

	@Override
	public void onEntityAdded(BaseEntity entity) {
		if (entity instanceof IState) {
			stateEntities.put(entity.id, (IState) entity);
		}
	}

	@Override
	public void onEntityRemoved(BaseEntity entity) {
		if (entity instanceof IState) {
			stateEntities.remove(entity.id);
		}
	}

	@Override
	public void run(float delta) {
		for (IState IState : stateEntities.values()) {
			IState.changeToPreviousState();
		}
	}
}
